package bean_life;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@Component
public class BeanLifeComponent implements BeanNameAware, BeanFactoryAware, BeanClassLoaderAware, InitializingBean {
    @Override
    public void setBeanName(String name) {
        System.out.println("执行了通知setBeanName：" + name);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("执行了通知setBeanFactory：" + beanFactory.getClass().getName());
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("执行了通知setBeanClassLoader：" + classLoader.getClass().getName());
    }

//    @PostConstruct
    public void postConstruct(){
        System.out.println("通过注解@PostConstruct执行了初始化方法");
    }

    public void useBean(){
        System.out.println("开始使用bean");
    }

    public void dowith(){
        System.out.println("处理业务逻辑");
    }

//    @PreDestroy
    public void destoryBean(){
        System.out.println("执行销毁方法");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("执行了afterPropertiesSet");
    }
}
